package com.zgm.ch05.aop.pointcutAdvisor._4_1_4self1;

import org.springframework.aop.Advisor;
import org.springframework.aop.framework.ProxyFactory;
import org.springframework.aop.support.DefaultPointcutAdvisor;

import com.zgm.ch05.aop.pointcutAdvisor._4_1_3.SimpleAdvice;
import com.zgm.ch05.aop.pointcutAdvisor._4_1_4.SimpleBean;


public class DynamicPointcutExample {

	public static void main(String[] args) {
		SimpleBean target = new SimpleBean();
		SimpleBean2 target2 = new SimpleBean2();
		
		Advisor advisor = new DefaultPointcutAdvisor(new SimpleDynamicPointcut(), new SimpleAdvice());
		
		ProxyFactory pf = new ProxyFactory();
		pf.setTarget(target);
		pf.addAdvisor(advisor);
		
		SimpleBean proxy = (SimpleBean) pf.getProxy();
		
		
		proxy.foo(1);
		proxy.foo(10);
		proxy.foo(100);
		
		proxy.bar();
		proxy.bar();
		proxy.bar();
		
		System.out.println("/n/n============================/n/n");
		
		pf.setTarget(target2);////
		SimpleBean2 proxy2 = (SimpleBean2) pf.getProxy();//////
		proxy2.foo(1);
		proxy2.foo(10);
		proxy2.foo(100);
		
		proxy2.bar();
		proxy2.bar();
		proxy2.bar();
		
	}
}
